package com.digital.herbarium.Util;

import com.digital.herbarium.Entity.Stat;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

public class ArrUtil {


    public static <T> List<T> extendList(List<T> list, int size) {
        List<T> result = new ArrayList<>(list);
        while (result.size() < size) {
            result.add((T) (Integer) 0);  // 将0强制转换为T类型
        }
        return result;
    }


    public static  Double check(List<Stat> slist, String value){
        AtomicReference<Double> d = new AtomicReference<>(0.0);
        slist.forEach(stat -> {
            if(stat.getName().equals(value)){
                d.set(stat.getValue());
                return;
            }
        });
        return d.get();
    }


    public static double twoRound(double data){
        BigDecimal two11 = new BigDecimal(data);
        return two11.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}
